package cn.tedu.charging.user.dao.repository;

import cn.tedu.charging.user.dao.mapper.UserMapper;
import cn.tedu.charging.user.pojo.po.UserPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class UserRepositoryImpl implements UserRepository{
  @Autowired
  private  UserMapper userMapper;
    @Override
    public UserPO getUserByOpenId(String openId) {
        QueryWrapper<UserPO> queryWrapper = new QueryWrapper<UserPO>();
        queryWrapper.eq("wx_open_id", openId);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public Integer save(String openId, String nickName) {
        UserPO userPO = new UserPO();
        userPO.setWxOpenId(openId);
        userPO.setNickName(nickName);
        //mybaits-plus 保存成功后 自动获取自增的id,放入PO
        //mybaits 在MyBatis中，如果你想获取插入操作后生成的自增ID，
        // 你可以在mapper的XML文件中的<insert>标签中
        // 使用useGeneratedKeys属性和keyProperty属性
        userMapper.insert(userPO);
        return userPO.getId();
    }
}
